package cn.pet_know.common.my_exception;

import cn.pet_know.common.enums.RCode;
import cn.pet_know.common.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 自定义异常
     */
    @ExceptionHandler(CustomException.class)
    public R customError(CustomException e){
        return R.fail(e.getMessage(), RCode.CUSTOM.getCode());
    }
    @ExceptionHandler(Exception.class)
    public R unKonwError(Exception e){
        log.error(e.getMessage());
        return R.fail("网络开小差了~~",RCode.FAIL.getCode());
    }
}
